﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Security.Principal;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Channels;
using CHPM.IC.Logger;
using CHPM.IC.ServiceLocator;
using CHPM.IC.ObjectMapper;

namespace CHPM.SL.TheService.Code
{
    public abstract class BaseService
    {
        #region Constants

        protected const string NO_PERMISSIONS_EXCEPTION_MESSAGE = "No permissions for access the function";

        #endregion

        #region Fields

        private readonly IServiceLocator _serviceLocator;

        #endregion

        #region Constructors

        public BaseService(IServiceLocator serviceLocator)
        {
            this._serviceLocator = serviceLocator;
        }

        #endregion

        #region Protected Properties

        protected virtual IServiceLocator ServiceLocator
        {
            get
            {
                return this._serviceLocator;
            }
        }

        protected virtual IObjectMapper ObjectMapper
        {
            get
            {
                return this.ServiceLocator.Resolve<IObjectMapper>();
            }
        }

        protected virtual ILogger ErrorLogger
        {
            get
            {
                return this.ServiceLocator.Resolve<ILogger>();
            }
        }

        #endregion

        #region Protected Members

        protected IIdentity GetCurrentConsumerIdentity()
        {
            return OperationContext.Current.ServiceSecurityContext.PrimaryIdentity;
        }

        #endregion
        
    }
}
